package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.UserOrder;
import cn.wolfcode.trip.base.service.IUserOrderService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class UserOrderController {
    @Autowired
    private IUserOrderService userOrderService;




    /*
     * 查询对应订单号的订单信息
     * 资源:/hotels/recommend
     * 动作:GET
     * 参数:keyword
     * */
    @GetMapping("/{orderNumber}/orderNumber")
    public Object getHotelByRecommend(@PathVariable String orderNumber){
        return userOrderService.selectByUUID(orderNumber);
    }











    /*
     * 保存订单信息
     * 资源:/order/{indentid}
     * 动作:POST
     * 参数:
     * */
    @PostMapping("/indent")
    public Object updateByIndentId(UserOrder userOrder){
            userOrderService.saveOrUpdateLeading(userOrder);
        return new JSONResult();
    }




    /*
     * 根据对应商品id的订单
     * 资源:/order/{id}
     * 动作:get
     * 参数:
     * */
    @GetMapping("/{id}")
    public Object getProductsById(@PathVariable Long id){
        return userOrderService.selectByProductId(id);
    }


    /*
     * 根据订单id获取订单信息
     * 资源:/order/{indentid}
     * 动作:get
     * 参数:
     * */
    @GetMapping("/{id}/indent")
    public Object getProductsByIndentId(@PathVariable Long id){
        return userOrderService.selectByIndentId(id);
    }
    /*
     * 修改对应订单id订单信息
     * 资源:/order/{indentid}
     * 动作:get
     * 参数:
     * */
    @PutMapping("/{id}/indent")
    public Object updateByIndentId(@PathVariable Long id,Integer state,Long userId){
        if(id!=null){
            userOrderService.updateByIndentId(id,state,userId);
        }
        return new JSONResult();
    }
}
